<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
    <title>智慧社区-物业管理</title>

    <meta name="description" content="Dashboard" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/assets/img/favicon.png" type="image/x-icon">
    <link href="${pageContext.request.contextPath}/resource/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/font-awesome.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/animate.min.css" rel="stylesheet" />
	<script src="${pageContext.request.contextPath}/resource/assets/js/skins.min.js"></script>
</head>
<body>
<%@include file="../header.jsp" %>
	<!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <!-- Page Sidebar -->
            <%@include file="../nav.jsp" %><!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb" style="margin-top: 8px;">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li><a href="#">社区黄页</a></li>
                        <li class="active">添加黄页</li>
                    </ul>
                </div><!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <div class="header-title" style="margin-top: 2px;">
                        <h1>
                            添加黄页
                        </h1>
                    </div><!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div><!--Header Buttons End-->
                </div><!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                	<div class="row">
	                	<div class="col-lg-6 col-sm-6 col-xs-12">
	                		<div class="widget">
                                        <div class="widget-header bordered-bottom bordered-palegreen">
                                            <span class="widget-caption">添加黄页</span>
                                        </div>
                                        <div class="widget-body">
                                           <div id="registration-form">
                                                        <form role="form">
                                                            <div class="form-title">
                                                            	黄页信息
                                                            </div>
                                                            	<div class="form-group">
                                                                        <span class="input-icon icon-right">
                                                                            <input type="text" class="form-control" placeholder="所属小区" value="${loginUser.loginVillage.name}" disabled>
                                                                            <i class="glyphicon glyphicon-globe"></i>
                                                                       </span>
                                                              	</div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="name" type="text" class="form-control"  placeholder="黄页名称" value="${yp.name }">
                                                                    <i class="glyphicon glyphicon-align-right"></i>
                                                                </span>
                                                            </div>
                                                            
                                                             <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="address" type="text" class="form-control" placeholder="地址" value="${yp.address }">
                                                                    <i class="glyphicon glyphicon-map-marker"></i>
                                                                </span>
                                                            </div>
                                                             
                                                          <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="phone" type="text" class="form-control" placeholder="联系电话" value="${yp.phoneNumber }">
                                                                    <i class="glyphicon glyphicon-map-marker"></i>
                                                                </span>
                                                            </div>
                                                           
                                                            <hr class="wide" />
                                                            <div class="row" style="text-align: right;margin-right: 10px;">
                                                            	<button type="button" class="btn btn-warning" onclick="cancel()"> 取 消 </button>
                                                            	<button type="button" class="btn btn-blue" onclick="save()"> 添 加 </button>
                                                            </div>
                                                            
                                                        </form>
                                                    </div> 
                                        </div>
                                    </div>
	                	</div>
                	
                    </div>
                </div><!-- /Page Body -->
             </div><!-- /Page Content -->
     	</div><!-- /Page Container -->
     </div><!-- /Main Container -->
     	<script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/bootstrap.min.js"></script>
    <!--Beyond Scripts-->
    <script src="${pageContext.request.contextPath}/resource/assets/js/beyond.min.js"></script>
    <script type="text/javascript">
    	$('.loading-container').hide();
    	$('#menu_yellow').addClass("active open");
		$('#menu_yellowadd').addClass("active");
    	var objectId = "${yp.objectId}";
    	 function validate(number){  
    	        var reg = new RegExp("^(0?1[358]\d{9})$|^((0(10|2[1-3]|[3-9]\d{2}))?[1-9]\d{6,7})$");  
    	         
    		     if(!reg.test(number)){  
    		        return false;  
    		     }  
    		     
    	     	return true;
    	   }  
    	function save(){
    		var name = $.trim($('#name').val());
    		var address = $.trim($('#address').val());
    		var phoneNumber = $.trim($('#phone').val());
    		
    		if(name == "" || address == ""){
    			alert("请完善信息后再保存~");
    			return;
    		}
    		
    		if(!validate(phoneNumber)){
    			alert("请填写正确的电话号码");
    			return;
    		}
    		
    		$('.loading-container').show();
    		$.ajax({
    			"url":"yellow_save",
    			"data":{objectId:objectId,name:name,address:address,phoneNumber:phoneNumber},
    			"type":'post',
    			"dataType":'json',
    			"success" : function(result) {
    				$('.loading-container').hide();
    				
    				if (result == 201){
    					alert("鉴权已过期，请重新登录");
    					location.href="/WisdomHome";
    					return;
    				}
    				
    				if (result == 200) {
    					alert("黄页保存成功");
    					cancel();
    				}else {
    					alert("提交失败，请检查网络后重试~");
    				}
    			},
    			"error" : function(msg) {
    				alert("error msg:"+msg.responseText);
    			}
    		});
    	}
    	
    	function cancel(){
    		$('#name').val("");
			$('#address').val("");
			$('#phone').val("");
    	}
    	
    	
    </script>
</body>
</html>